Can't find what you're looking for?
Hit the online chat button bottom left, or click the contact Kademi button below.
By default kademi has two login forms:
Note that initialising the user plugin isnt just for login. It also initialises javascript variables from cookies, applies user state classes to make things visible or hidden depending on whether there is a user logged in, and provides a logout function.
<script type="text/javascript" src="/theme/js/jquery.user.js">//</script>
So far so good...
Here's a simple bootstrap form:
<form class="login form-horizontal form-horizontal-block" method="POST" role="form"> <p class="login message" style="display: none">.</p> <div class="form-group"> <label for="email" class="control-label col-md-4">Email</label> <div class="col-md-8"> <input type="text" autocapitalize="off" autocorrect="off" class="form-control" required="true" name="email" id="email" title="Email address" placeholder="Enter your email address" /> </div> </div> <div class="form-group"> <label for="password" class="control-label col-md-4">Password</label> <div class="col-md-8"> <input type="password" class="form-control" required="true" name="password" id="password" title="Password" placeholder="Enter your password" /> </div> </div> <div class="form-group"> <div class="col-md-offset-4 col-md-8"> <button type="submit" class="btn btn-sm btn-primary"><span>Login</span></button> <a class="Forgot" title="Forgotten password" href="/password-reset">Forgotten password</a> </div> </div> </form>
<script type="text/javascript">
$(function () {
jQuery(".login-container").user({
afterLoginUrl: window.location.pathname,
valiationMessageSelector: "p.login.message"
}); // setup login and logout
});
</script>
The plugin has the default logout selector of ".logout", which is configured in the logoutSelector property. Whenever a matching element is clicked the doLogout function is called:
$(config.logoutSelector).click(function() {
doLogout();
});
If you dont want to use the jquery.user plugin, you can create an ajax request to login as follows:
URL: /.dologin
Method: POST
Parameters:
_loginPassword |
|
_loginUserName |
|
The response is JSON like this. Be sure to check the status property
{"data":{ "name":"XXX", "href":"/users/XXX/public", "userName":"XXX", "userId":99999, "photoHash": "0f672c686fdf25f1957fca84e4b1f5c944b5cadf"}, "fieldMessages":[], "messages":[], "nextHref":"", "status":true }
| Property | Meaning |
| name | The publicly viewable name of this user, like a nickname |
| href | Path to the publicly accessible profile page |
| userName | The unique identifier for this user |
| userId | The internal unique identifier |
| photoHash | The hash of the user's profile photo. Can be loaded from /_hashes/files/XXX |
| fieldMessages | Any login validation messages specific to fields, ie username or password. Standard property of JsonResult |
| messages | Any validation messages not specific to a field, standard property of JsonResult |
| nextHref | The next page to go to if there is a server side page workflow in progress, standard property of JsonResult |
| status | True if the login was successful |
Whenever a user attempts to access a secure resource and is not authorised the login template is rendered. The template is /theme/apps/login/login.html and you can see the default bootstrap 3.2 login template here
Since the login template is rendered in places of the actual page, bookmarks are accessible without redirects to a specific login page. To prevent caching of the login template the response is returned with 400 HTTP status code.
A common pattern is to redirect users away from a page when they are not authorised to access it. We recommend against this practise in Kademi.
Instead we recommend having an explicit login and/or registration process (eg on a landing page) and also have a login template which is displayed on access to a secure resource.
The advantage of a login template is that it can display an appropriate message when there is a logged in user who is being denied access, versus the situation where the user simply has not logged in. Even if you have an "all or nothing" permission strategy this is preferable because it will help you diagnose incorrect permissions. And in most cases websites evolve from all-or-nothing to have at least a few role dependent resources over time.
Hit the online chat button bottom left, or click the contact Kademi button below.